# TODO: Add comment
# 
# Author: Forever
###############################################################################
met_data = read.csv("C:/in/AvgTempPress.csv")

inputPath = "C:/in2"
inputFile = "npp_data"
listFile = list.files(path = inputPath,pattern=inputFile,full.names = TRUE,recursive=TRUE)
Size = length(listFile)
for(i in 1:Size){
	filename = listFile[i]
	data = read.csv(filename)
	
	colnames(data)[1] = "station"
	colnames(data)[2] = "year"
	colnames(data)[3] = "month"
	colnames(data)[4] = "aqstime"
	colnames(data)[5] = "pm1"
	colnames(data)[6] = "pm25"
	colnames(data)[7] = "pm10"
	colnames(data)[8] = "aod"
	colnames(data)[9] = "temp"

	total_row = nrow(data)
	data$area_id = c(1:total_row)
	
	data$area_id[data$station==1]<-3
	data$area_id[data$station==2]<-4
	data$area_id[data$station==3]<-5
	data$area_id[data$station==4]<-2
	data$area_id[data$station==5]<-5
	
	
	final = merge(data,met_data,c("area_id","month"))
	
	out_file = substr(filename,1,nchar(filename)-4)
	out_file = paste(out_file,"_merge.csv",sep="")
	write.csv(final,out_file)
	
}

print("Done")
